package jmm.threadPool.completionService;

import com.sun.org.apache.xpath.internal.operations.Bool;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class CompletionServiceDemo1 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        // 创建线程池
        ExecutorService executor =
                Executors.newFixedThreadPool(3);

        List<Future<String>> list = new ArrayList<>();
        CompletionService<String> completionService = new ExecutorCompletionService(executor);


        for (int i = 0; i < 5; i++) {

            int finalI = i;
            list.add(completionService.submit(()->{
                System.out.println("开始---");

                return String.valueOf(finalI);
            }));
        }

        for (Future<String> booleanFuture : list) {
            System.out.println(booleanFuture.get());;
        }
    }
}
